<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.7.6/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form" lay-filter="my_form">
            <div class="layui-form-item">
                <label class="layui-form-label required">花店名称</label>
                <div class="layui-input-block">
                    <input type="text" name="shop_name" lay-verify="required" lay-reqtext="花店名称不能为空" placeholder="请输入花店名称"  value="秋野花舍" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">当前节日</label>
                <div class="layui-input-block">
                    <select name="holiday_type" id="holiday_type" lay-verify="required">
                        <option value=""></option>
                        <option value="0">其他</option>
                        <option value="1">情人节</option>
                        <option value="2">七夕</option>
                        <option value="3">520</option>
                        <option value="4">妇女节</option>
                        <option value="5">教师节</option>
                        <option value="6">母亲节</option>
                        <option value="7">圣诞节</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="setting">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/static/lib/layui-v2.7.6/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form
            ,$ = layui.$
            , layer = layui.layer;

        $.ajax({
            url: "/config/index",
            type: 'get',
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            data:{},
            success: function (obj) {
                //表单初始赋值
                form.val('my_form', {
                    "shop_name": obj.data.shop_name,
                    "holiday_type": obj.data.holiday_type,
                })
                form.render('select');
            },
            error: function (xhr, textstatus, thrown) {
                layer.msg('网络错误');
            }
        });
        //监听提交
        form.on('submit(setting)', function (data) {
            // parent.layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // });
            $.ajax({
                url: "/config/edit",
                type: 'post',
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                data:JSON.stringify({
                    "shop_name": data.field.shop_name,
                    "holiday_type": data.field.holiday_type,
                }),
                async: false,
                success: function (ret) {
                    var msg = ret.code > 0  ? ret.msg : "保存成功" ;
                    layer.msg(msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        parent.layui.table.reload('currentTableId',{page:{curr:1}})
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                },
                error: function (xhr, textstatus, thrown) {
                    layer.msg('保存失败');
                }
            });
            return false;
        });

    });
</script>
</body>
</html>